package com.aaa.demo05;

/**
 * @author ${崔灿}
 * @date 2022/11/01 15:49
 **/

public class TestYield {
    public static void main(String[] args) {
        YieldDDemo t1 = new YieldDDemo();
        YieldDDemo t2 = new YieldDDemo();
        t1.start();
        t2.start();
    }
}
class YieldDDemo extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            //当前线程放弃时间片，进入就绪状态，参与下次cpu时间片的竞争 可能出现交替的频率比较高
            Thread.yield();
            System.out.println(Thread.currentThread().getName()+"***"+i);
}
    }
}
